package com.burstly.lib.component.networkcomponent.burstly;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint.Align;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.MeasureSpec;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.util.ArrayList;
import java.util.List;

final class TextViewMultilineEllipse extends View
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private int mAscent;
  private LineBreaker mBreakerCollapsed = new LineBreaker();
  private LineBreaker mBreakerExpanded = new LineBreaker();
  private int mColorEllipsizeMore = -16776961;
  private boolean mDrawEllipsizeMoreString = true;
  private boolean mExpanded = false;
  private int mMaxLines = 2;
  private boolean mRightAlignEllipsizeMoreString = false;
  private String mStrEllipsis = "...";
  private String mStrEllipsisMore = "";
  private String mText;
  private TextPaint mTextPaint = new TextPaint();

  public TextViewMultilineEllipse(Context paramContext)
  {
    this(paramContext, null);
  }

  public TextViewMultilineEllipse(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.mTextPaint.setAntiAlias(true);
    this.mTextPaint.setTextSize(15.0F * Utils.getScale(paramContext));
    this.mTextPaint.setColor(-1);
    this.mTextPaint.setTextAlign(Paint.Align.LEFT);
  }

  private int breakWidth(int paramInt)
  {
    if (this.mExpanded);
    for (int i = this.mBreakerExpanded.breakText(this.mText, paramInt - getPaddingLeft() - getPaddingRight(), this.mTextPaint); ; i = this.mBreakerCollapsed.breakText(this.mText, this.mStrEllipsis, this.mStrEllipsisMore, this.mMaxLines, paramInt - getPaddingLeft() - getPaddingRight(), this.mTextPaint))
      return i + getPaddingLeft() + getPaddingRight();
  }

  private int measureHeight(int paramInt)
  {
    int i = View.MeasureSpec.getMode(paramInt);
    int j = View.MeasureSpec.getSize(paramInt);
    this.mAscent = ((int)this.mTextPaint.ascent());
    int m;
    if (i == 1073741824)
    {
      m = j;
      return m;
    }
    if (this.mExpanded);
    for (int k = this.mBreakerExpanded.getLines().size(); ; k = this.mBreakerCollapsed.getLines().size())
    {
      m = k * (int)(-this.mAscent + this.mTextPaint.descent()) + getPaddingTop() + getPaddingBottom();
      if (i != -2147483648)
        break;
      return Math.min(m, j);
    }
  }

  private int measureWidth(int paramInt)
  {
    int i = View.MeasureSpec.getMode(paramInt);
    int j = View.MeasureSpec.getSize(paramInt);
    if (i == 1073741824)
    {
      breakWidth(j);
      return j;
    }
    if (i == -2147483648)
      return Math.min(breakWidth(j), j);
    breakWidth(j);
    return 0;
  }

  public void collapse()
  {
    this.mExpanded = false;
    requestLayout();
    invalidate();
  }

  public void expand()
  {
    this.mExpanded = true;
    requestLayout();
    invalidate();
  }

  public boolean isExpanded()
  {
    return this.mExpanded;
  }

  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    LineBreaker localLineBreaker;
    List localList;
    float f1;
    float f2;
    if (this.mExpanded)
    {
      localLineBreaker = this.mBreakerExpanded;
      localList = this.mBreakerExpanded.getLines();
      f1 = getPaddingLeft();
      f2 = getPaddingTop() + -this.mAscent;
    }
    label269: label314: for (int i = 0; ; i++)
      try
      {
        int k;
        if (i < localList.size())
        {
          int[] arrayOfInt = (int[])localList.get(i);
          paramCanvas.drawText(this.mText, arrayOfInt[0], 1 + arrayOfInt[1], f1, f2, this.mTextPaint);
          if ((i == -1 + localList.size()) && (localLineBreaker.isRequiredEllipsis()))
          {
            paramCanvas.drawText(this.mStrEllipsis, f1 + localLineBreaker.getLengthLastEllipsizedLine(), f2, this.mTextPaint);
            if (this.mDrawEllipsizeMoreString)
            {
              k = this.mTextPaint.getColor();
              this.mTextPaint.setColor(this.mColorEllipsizeMore);
              if (!this.mRightAlignEllipsizeMoreString)
                break label269;
              paramCanvas.drawText(this.mStrEllipsisMore, paramCanvas.getWidth() - (localLineBreaker.getLengthEllipsisMore() + getPaddingRight() + getPaddingLeft()), f2, this.mTextPaint);
            }
          }
        }
        while (true)
        {
          this.mTextPaint.setColor(k);
          f2 += -this.mAscent + this.mTextPaint.descent();
          int j = paramCanvas.getHeight();
          if (f2 <= j)
            break label314;
          return;
          localLineBreaker = this.mBreakerCollapsed;
          localList = this.mBreakerCollapsed.getLines();
          break;
          paramCanvas.drawText(this.mStrEllipsisMore, f1 + localLineBreaker.getLengthLastEllipsizedLinePlusEllipsis(), f2, this.mTextPaint);
        }
      }
      catch (IndexOutOfBoundsException localIndexOutOfBoundsException)
      {
        LOG.logError("TextViewMultilineEllipse", localIndexOutOfBoundsException.getMessage(), new Object[0]);
        return;
      }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    setMeasuredDimension(measureWidth(paramInt1), measureHeight(paramInt2));
  }

  public void setColorEllpsizeMore(int paramInt)
  {
    this.mColorEllipsizeMore = paramInt;
  }

  public void setDrawEllipsizeMoreString(boolean paramBoolean)
  {
    this.mDrawEllipsizeMoreString = paramBoolean;
  }

  public void setEllipsis(String paramString)
  {
    this.mStrEllipsis = paramString;
  }

  public void setEllipsisMore(String paramString)
  {
    this.mStrEllipsisMore = paramString;
  }

  public void setMaxLines(int paramInt)
  {
    this.mMaxLines = paramInt;
  }

  public void setRightAlignEllipsizeMoreString(boolean paramBoolean)
  {
    this.mRightAlignEllipsizeMoreString = paramBoolean;
  }

  public void setText(String paramString)
  {
    this.mText = paramString;
    requestLayout();
    invalidate();
  }

  public void setTextColor(int paramInt)
  {
    this.mTextPaint.setColor(paramInt);
    invalidate();
  }

  public void setTextSize(int paramInt)
  {
    this.mTextPaint.setTextSize(paramInt);
    requestLayout();
    invalidate();
  }

  private static class LineBreaker
  {
    private float mLengthEllipsis;
    private float mLengthEllipsisMore;
    private float mLengthLastLine;
    private ArrayList<int[]> mLines = new ArrayList();
    private boolean mRequiredEllipsis = false;

    public int breakText(String paramString, int paramInt, TextPaint paramTextPaint)
    {
      return breakText(paramString, null, null, -1, paramInt, paramTextPaint);
    }

    public int breakText(String paramString1, String paramString2, String paramString3, int paramInt1, int paramInt2, TextPaint paramTextPaint)
    {
      this.mLines.clear();
      this.mRequiredEllipsis = false;
      this.mLengthLastLine = 0.0F;
      this.mLengthEllipsis = 0.0F;
      this.mLengthEllipsisMore = 0.0F;
      if (paramInt2 == -1)
      {
        ArrayList localArrayList2 = this.mLines;
        int[] arrayOfInt3 = new int[2];
        arrayOfInt3[0] = 0;
        arrayOfInt3[1] = paramString1.length();
        localArrayList2.add(arrayOfInt3);
        return (int)(0.5F + paramTextPaint.measureText(paramString1));
      }
      if (paramString2 != null)
        this.mLengthEllipsis = paramTextPaint.measureText(paramString2);
      if (paramString3 != null)
        this.mLengthEllipsisMore = paramTextPaint.measureText(paramString3);
      int i = -1;
      float f1 = 0.0F;
      int j = 1;
      int k = 0;
      if (k < paramString1.length())
      {
        if (i == -1)
          i = k;
        if (this.mLines.size() != paramInt1)
          break label215;
        this.mRequiredEllipsis = true;
      }
      label215: float f2;
      while (true)
      {
        if (this.mRequiredEllipsis)
        {
          int[] arrayOfInt1 = (int[])this.mLines.get(-1 + this.mLines.size());
          this.mLengthLastLine = paramTextPaint.measureText(paramString1.substring(arrayOfInt1[0], 1 + arrayOfInt1[1]));
        }
        if (this.mLines.size() != 0)
          break label558;
        return 0;
        f2 = paramTextPaint.measureText(paramString1.charAt(k) + "");
        if (paramString1.charAt(k) != '\n')
          break;
        m = 1;
        ArrayList localArrayList1 = this.mLines;
        int[] arrayOfInt2 = new int[2];
        arrayOfInt2[0] = i;
        arrayOfInt2[1] = (k - 1);
        localArrayList1.add(arrayOfInt2);
        if (k <= i)
        {
          this.mRequiredEllipsis = true;
        }
        else
        {
          if ((paramTextPaint.measureText(paramString1.substring(i, k - 1)) >= paramInt2) || (this.mLines.size() != paramInt1))
            break label412;
          this.mRequiredEllipsis = false;
        }
      }
      boolean bool = f1 + f2 < paramInt2;
      int m = 0;
      if (!bool)
      {
        m = 1;
        if ((paramString1.charAt(k) == ' ') || (j == 0))
        {
          k--;
          this.mLines.add(new int[] { i, k });
        }
      }
      else
      {
        label412: if (m == 0)
          break label516;
        i = -1;
        int n = this.mLines.size();
        int i1 = paramInt1 - 1;
        f1 = 0.0F;
        if (n == i1)
        {
          paramInt2 = (int)(paramInt2 - (this.mLengthEllipsis + this.mLengthEllipsisMore));
          j = 0;
        }
      }
      while (true)
      {
        k++;
        break;
        while ((k >= 0) && (paramString1.charAt(k) != ' '))
          k--;
        this.mLines.add(new int[] { i, k });
        break label412;
        label516: f1 += f2;
        if (k == -1 + paramString1.length())
          this.mLines.add(new int[] { i, k });
      }
      label558: if (this.mLines.size() == 1)
        return (int)(0.5F + paramTextPaint.measureText(paramString1));
      return paramInt2;
    }

    public float getLengthEllipsisMore()
    {
      return this.mLengthEllipsisMore;
    }

    public float getLengthLastEllipsizedLine()
    {
      return this.mLengthLastLine;
    }

    public float getLengthLastEllipsizedLinePlusEllipsis()
    {
      return this.mLengthLastLine + this.mLengthEllipsis;
    }

    public List<int[]> getLines()
    {
      return this.mLines;
    }

    public boolean isRequiredEllipsis()
    {
      return this.mRequiredEllipsis;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.TextViewMultilineEllipse
 * JD-Core Version:    0.6.2
 */